<template>
	<uni-forms class="login-form" ref="form" :model="fromData" :rules="rulesFrom">
		<uni-forms-item name="account">
			<input type="text" placeholder="请输入账号" v-model="fromData.account" class="uni-input-input" placeholder-style="color: #818181" />
		</uni-forms-item>
		<uni-forms-item name="password">
			<input type="text" placeholder="请输入密码" v-model="fromData.password" class="uni-input-input" placeholder-style="color: #818181" />
		</uni-forms-item>
		<button class="submit-button" @click="login">登录</button>
	</uni-forms>
</template>

<script setup>
//导入 request
import { loginFrom } from '@/apis/login.js';
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { useUserStore } from '@/stores/user.js';
const store = useUserStore();
const fromData = ref({
	account: 'wang9986', //账号
	password: '123456' //密码
}); // 账号
//校验
const rulesFrom = ref({
	account: {
		rules: [{ required: true, errorMessage: '请输入登录账号' }]
	},
	password: {
		rules: [{ required: true, errorMessage: '请输入登录密码' }]
	}
});

const qwer = {}; //获取 历史页面
onLoad((query) => {
	//获取 历史页面
	// redirectURL.value = query.redirectURL;
	console.log('redirectURL路径', query.redirectURL);
});

//点击登录
const form = ref();
const login = async () => {
	//兜底校验
	const fromData = await form.value.validate();
	const res = await loginFrom(fromData);
	// console.log('登录', res.data);
	store.setToken(res.data);
	//跳转到登录页
	// const URL = res ===
	uni.utils.push('/pages/task/index');
};
</script>

<style lang="scss" scoped>
@import './styles.scss';
</style>
